var str = location.search;
var bool;
str = str.slice(1).split('&');
var json = {};
for(var i = 0; i < str.length; i++) {
    var a = str[i].split('=');
    json[a[0]] = a[1];
}
console.log(json);

$(function() {
	init();
	//lookUp();
});
$(".form-datetime").datetimepicker(
    {
        language:  "zh-CN",
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0,
        format: "yyyy-mm-dd"
    });
function init() {
    //table1表格的显示


    $("#pjTable").bootstrapTable({
        method: "post",
        url: "http://192.168.59.3:8082/console/projectcapital/getProjectTeamCapital",
        contentType: "application/json",
        queryParams: function (params) {
            params.pageNum = 1;
            params.pageSize = 10;
            params.projectCode = json.projectCode;
            params.teamUserCode = $(".order-num>input").eq(0).val();
            params.teamUserName = $(".order-num>input").eq(1).val();

            console.log(params);
            return params;
        },
        onClickRow: function (row, value) {
            var str = "";
            for (var key in row) {
                str += "&" + key + "=" + row[key];
            }
            layer.open({
                type: 2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: `transferDetails.html?${str.slice(1)}`
            });
        },
        responseHandler: function (res) {
            console.log(res);
            return {rows: res.data.list, total: res.data.total};
        }
    });
    //	table2的表单显示
    $("#pjTable1").bootstrapTable({
        method: "post",
        url: "http://192.168.59.3:8082/console/projectcapital/getShopCapitalListByType",
        contentType: "application/json",
        queryParams: function (params) {
            params.pageNum = 1;
            params.pageSize = 10;
            params.projectCode = json.projectCode;
            params.type = 1;
            params.teamUserCode = $(".order-num1>input").eq(0).val();
            params.supplierUserName = $(".order-num1>input").eq(1).val();
            params.month = $(".inpDate").val();
            console.log(params);
            return params;
        },
        onClickRow: function (row, value) {
            var str = "";
            for (var key in row) {
                str += "&" + key + "=" + row[key];
            }
            layer.open({
                type: 2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: `equipmentReport.html?${str.slice(1)}`
            });
        },
        onLoadSuccess: function (data) {
            console.log(data);
        }
    });
    //	table3的表单显示
    $("#pjTable2").bootstrapTable({
        method: "post",
        url: "http://192.168.59.3:8082/console/projectcapital/getShopCapitalListByType",
        contentType: "application/json",
        queryParams: function (params) {
            params.pageNum = 1;
            params.pageSize = 10;
            params.projectCode = json.projectCode;
            params.type = 2;
            params.teamUserCode = $(".order-num2>input").eq(0).val();
            params.supplierUserName = $(".order-num2>input").eq(1).val();
            params.month = $(".inpDate").val();
            console.log(params);
            return params;
        },
        onClickRow: function (row, value) {
            var str = "";
            for (var key in row) {
                str += "&" + key + "=" + row[key];
            }
            layer.open({
                type: 2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: `materialReport.html?${str.slice(1)}`
            });
        },
        responseHandler: function (res) {
            console.log(res);
            return {rows: res.data.list, total: res.data.total};
        },
        onLoadSuccess: function (data) {
            console.log(data);
        }
    });

    //		在table4中显示
    $("#pjTable3").bootstrapTable({
        method: "post",
        url: "http://192.168.59.3:8082/console/projectcapital/getShopCapitalListByType",
        contentType: "application/json",
        queryParams: function (params) {
            params.pageNum = 1;
            params.pageSize = 10;
            params.projectCode = json.projectCode;
            params.type = 3;
            params.teamUserCode = $(".order-num3>input").eq(0).val();
            params.supplierUserName = $(".order-num3>input").eq(1).val();
            params.month = $(".inpDate").val();
            console.log(params);
            return params;
        },
        onClickRow: function (row, value) {
            var str = "";
            for (var key in row) {
                str += "&" + key + "=" + row[key];
            }
            layer.open({
                type: 2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: `platformReport.html?${str.slice(1)}`
            });
        },
        responseHandler: function (res) {
            console.log(res);
            return {rows: res.data.list, total: res.data.total};
        },
        onLoadSuccess: function (data) {
            console.log(data);
        }
    });
//搜索的点击 刷新表格
    $("#searchOption").click(function () {
        $("#pjTable").bootstrapTable("refresh");

    });
// 表格2
    $("#searchOption1").click(function () {
        $("#pjTable1").bootstrapTable("refresh");

    });
    $("#searchOption2").click(function () {
        $("#pjTable2").bootstrapTable("refresh");

    });
    $("#searchOption3").click(function () {
        $("#pjTable3").bootstrapTable("refresh");

    });

//  清空操作
    $("#clearoption").click(function () {
        $(".order-num>input").eq(0).val('');
        $(".order-num>input").eq(1).val('');
        $("#pjTable").bootstrapTable("refresh");

    });
// 表格2
    $("#clearOption1").click(function () {
        $(".order-num1>input").eq(0).val('');
        $(".order-num1>input").eq(1).val('');
        $("#pjTable1").bootstrapTable("refresh");

    });

    $("#clearOption2").click(function () {
        $(".order-num2>input").eq(0).val('');
        $(".order-num2>input").eq(1).val('');
        $("#pjTable2").bootstrapTable("refresh");

    });
    $("#clearOption3").click(function () {
        $(".order-num3>input").eq(0).val('');
        $(".order-num3>input").eq(1).val('');
        $("#pjTable3").bootstrapTable("refresh");

    });
    function responseHandler(response) {
        var needData = {
            rows: response.data.list,
            total: response.data.total
        };
        return needData;
    }

    function resHandler(response) {

        var needData = {
            rows: response.data.list,
            total: response.data.total
        };
        return needData;
    }

    function process(val, row, index) {
        console.log(row);
        return "<span>编辑</span>" + "<span class='editorWorker'>></span>";

    }

    function nuPay(val, row, index) {

        return row.currentNeedpay - row.currentHaspaid;

    }

    function indexFmt(val, row, index) {
        return index + 1;
    }

    function pjTableQuery(params) {
        params["pageNum"] = (params.offset / params.limit) + 1;
        params.pageSize = params.limit;
        params.projectCode = json.projectCode;
        return params;
    }

    function lookUp(res) {
        $('.form-group>input').keydown(function (e) {
            //console.log(this);
            var val = $(this).val();
            //
            var lName = $(this).prev().html().charCodeAt();

            var names = $('#pjTable>thead>tr>th');
            //console.dir(names);
            for (var i = 1; i < names.length; i++) {
                var key = names[i].innerText.charCodeAt();

                if (key == lName) {

                    var items = $(names[i]).attr("data-field");

                    var oHtmls = '',
                        oTd = '';

                }
            }
        });

    }
}


//资金设备的调用函数
// function meterialServe() {
//
// 	$.ajax({
// 		type: "get",
// 		url: "http://192.168.59.3:8082/console/projectcapital/getShopCapitalListDetail?merchandiseType=1&shopId=1&pageNum=1&pageSize=10&teamId=1",
//
// 	});
//
// }